package com.project.pushtask.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.project.pushtask.dto.ParamDto;
import com.project.pushtask.entity.Shike;
import com.project.pushtask.mapper.ShikeMapper;
import com.project.pushtask.service.ShikeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ShikeServiceImpl implements ShikeService {

    @Resource
    private ShikeMapper shikeMapper;

    @Override
    @DS("master")
    public List<Shike> getCreateList() {
        return shikeMapper.selectCreateList();
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    @DS("secondary")
    public void saveCreateList(List<Shike> list) {
        for (Shike entity : list) {
            shikeMapper.insertSelective(entity);
        }
    }
    @Override
    @DS("secondary")
    public Integer getCount(ParamDto paramDto) {
        return shikeMapper.getCount(paramDto);
    }

    @Override
    @DS("secondary")
    public List<Shike> getList(ParamDto paramDto) {
        return shikeMapper.getList(paramDto);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    @DS("secondary")
    public void deleteByDate(ParamDto paramDto) {
        shikeMapper.deleteByDate(paramDto);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    @DS("secondary")
    public void deleteExpireDate(ParamDto paramDto) {
        shikeMapper.deleteExpireDate(paramDto);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    @DS("readbase")
    public void saveList(List<Shike> list) {
        for (Shike entity : list) {
            shikeMapper.insertSelective(entity);
        }
    }

    @Override
    @DS("readbase")
    public Integer getReadBaseCount(ParamDto paramDto) {
        return shikeMapper.getCountReadbase(paramDto);
    }
}
